package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.CountOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public JobOption getEmpJobData() {//该方法调用empMapper.countEmpJobData()获取员工岗位统计数据，然后分别提取岗位名（pos）和对应人数（total），封装成JobOption对象返回
    List<Map<String,Object>> list = empMapper.countEmpJobData();
    List<Object> jobList = list.stream().map(dataMap->dataMap.get("pos")).toList();
    List<Object> dataList = list.stream().map(dataMap->dataMap.get("total")).toList();
    return new JobOption(jobList,dataList);
    }
//    第一个方法 getEmpJobData() 需要返回 JobOption 对象，而这个对象的构造函数要求传入两个独立的列表（岗位名列表和对应人数列表）
//    从查询结果中分别提取 "pos" 字段组成岗位名列表
//    从查询结果中分别提取 "total" 字段组成人数列表
//    再用这两个列表来构造 JobOption 对象


    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }
    //该方法调用empMapper.countEmpGenderData()获取员工性别统计数据，然后分别提取性别名（gender）和对应人数（total），封装成Map对象返回
    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    @Override
    public CountOption getStudentCountData() {
        List<Map<String,Object>> list = studentMapper.countStudentCountData();
        List<Object> clazzlist = list.stream().map(dataMap->dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap->dataMap.get("total")).toList();
        return new CountOption(clazzlist,dataList);
    }

}
